﻿using LightORM.Core.Extension;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections;
using System.Runtime.Caching;
using System.Collections.Generic;

namespace UnitTest
{


    /// <summary>
    ///This is a test class for BaseTypeExtensionTest and is intended
    ///to contain all BaseTypeExtensionTest Unit Tests
    ///</summary>
    [TestClass()]
    public class BaseTypeExtensionTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        [TestMethod]
        public void CollectionExtensionTest()
        {
            ArrayList arrayList = new ArrayList() { 12, 13 };
            Assert.IsFalse(arrayList.IsNullOrEmpty());

            Dictionary<int, string> dict = new Dictionary<int, string>() { { 1, "12" }, { 2, "113" } };

            Assert.IsFalse(dict.IsNullOrEmpty());

            arrayList = null;
            Assert.IsTrue(arrayList.IsNullOrEmpty());

            dict.Clear();
            Assert.IsTrue(dict.IsNullOrEmpty());

        }

        [TestMethod]
        public void RunTimeCacheTest()
        {


            ObjectCache cache = MemoryCache.Default;

            cache.Add(new CacheItem("zen", 1234), new CacheItemPolicy() { SlidingExpiration = TimeSpan.FromHours(1) });

            object item = cache.Get("zen");
            item = cache.Get("zen");
            item = cache.Get("zen");
            item = cache.Get("zen");
            item = cache.Get("zen");

            ////set cache
            //ObjectCache cache = MemoryCache.Default;

            ////add cache
            //List<string> listQuery = new List<string>
            //{
            //    "1","2"
            //};
            //CacheItemPolicy policy = new CacheItemPolicy();
            //policy.SlidingExpiration = TimeSpan.FromMinutes(60);
            //cache.Set("myCache", listQuery, policy);

            ////get cache
            //List<string> listResult = (List<string>)cache["myCache"];
            //foreach (string ary in listResult)
            //{
            //    Response.Write(ary);
            //}

        }


        /// <summary>
        ///A test for IsNullOrEmpty
        ///</summary>
        [TestMethod()]
        public void IsNullOrEmptyTest()
        {
            IDictionary dictionary = null; // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            actual = BaseTypeExtension.IsNullOrEmpty(dictionary);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
    }
}
